"""
    <VOLENV2
      ACT 1
      VIS 1
      ARM 1
      DEFSHAPE 0
      PT 0.000000 1.000000 0
      PT 2.000000 0.000000 0
      PT 4.000000 2.000000 0 0 1
      PT 6.000000 1.000000 0
    >
"""
"""
Volume for Track 1:
#Play-In       Vol(dB)
#----------- ---------
           0    -0.000
       88200   -96.330
      176400     6.000
      264600    -0.000
"""

"""
    <PANENV2
      ACT 1
      VIS 1
      ARM 1
      DEFSHAPE 0
      PT 0.000000 0.000000 0
      PT 2.000000 -1.000000 0
      PT 4.000000 1.000000 0 0 1
      PT 6.000000 0.000000 0
    >
"""

"""
Pan for Track 1:
#Play-In      Pan(0...2)
#----------- ---------
           0   1.00000
       88200   0.00000
      176400   2.00000
      264600   1.00000
"""

import math

# Define the calculations for conversion

def sl2rl(sl):
    """ samples to seconds """
    return sl/44100.0

def rl2sl(rl):
    """ seconds to samples """
    return "%12d" % int(rl * 44100)

def sv2rv(sv):
    return 2 ** ( sv / 6.0)

def rv2sv(rv):
    # 6 / math.log(2.0) = 8.6561702453337812
    # sv2rv(-96) = 1.52587890625e-005
    return 8.65617025 * math.log(rv+1.5258e-005)

def sp2rp(sp):
    return sp - 1.00000

def rp2sp(rp):
    return rp + 1.00000

# Calculations are working

# Start defining our search

def findall(L, value, start=0):
    i = start - 1
    try:
        i = L.index(value, i+i)
        yield i
    except ValueError:
        pass



if __name__ == '__main__':
    print rl2sl(0.000000)
    print rl2sl(2.000000)
    print rl2sl(4.000000)
    print rl2sl(6.000000)
    print rv2sv(1.000000)
    print rv2sv(0.000000)
    print rv2sv(2.000000)
    print rv2sv(1.000000)
    print sl2rl(           0)
    print sl2rl(       88200)
    print sl2rl(      176400)
    print rp2sp(0.000000)
    print rp2sp(-1.000000)
    print rp2sp(1.000000)
    print rp2sp(0.009890)
    print sp2rp(0.00099)
    edl = open('trackonly edl.RPP', 'r')
    realist = edl.readlines()
    for index in findall(realist, "VOLENV2"):
        print "match at", i
    
    

